#include <errno.h>
#include <signal.h>
#include <sys/mman.h>

char *block;

void tmhandler(sig, code, scp, addr)
int sig, code;
struct sigcontext *scp;
char *addr;
{
    int rc;

    printf("handling sigsegv addr=%d\n",addr);
    rc = mprotect((caddr_t)block,10,(PROT_READ | PROT_WRITE));
}

main()
{
    int i, rc;
    
    block = (char *) malloc(8192);
    i = (int) block;
    for ( ; i % 4096; i++)
	;
    block = (char *) i;
    /* rc = mprotect((caddr_t)block,10,(PROT_READ | PROT_WRITE)); */
    rc = mprotect((caddr_t)block,10,(PROT_READ));
    printf("rc=%d errno=%d block=%d\n",rc,errno,block);
    signal(SIGSEGV,tmhandler);
    *(block+1) = 'a';
    printf("%c\n",*(block+1));
}
